/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2008. All Rights Reserved.                             */
/* Open Source Software - may be modified and shared by FRC teams. The code   */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project.                                                               */
/*----------------------------------------------------------------------------*/
package edu.wpi.first.wpilibj.templates;

import edu.wpi.first.wpilibj.Timer;
import edu.wpi.first.wpilibj.Joystick;

/**
 * Thread that performs the actions when any buttons are pressed.
 * @author
 */
public class buttonThread extends Thread {

    private RobotMain mRobot997;
    private Joystick mLeftStick;
    private Joystick mRightStick;

    /**
     * The contructor.
     * @param A refernce to the 997 robot and its necessary objects.
     */
    public buttonThread(RobotMain robot) {
        mRobot997 = robot;
        mLeftStick = mRobot997.getLeftStick();
        mRightStick = mRobot997.getRightStick();
    }
    public void run() {
        while (mRobot997.isOperatorControl() && mRobot997.isEnabled()) {
            // DO NOT PUT ANY  CODE THAT TALKS TO THE MOTORS IN THIS THREAD!!!
            // All motor code should be in the main thread.
            if (mRightStick.getTrigger()) {
                mRobot997.performKick();
            }
            if (mRightStick.getRawButton(2)) {
                mRobot997.performSoftKick();
            }
            if(mRightStick.getRawButton(4)){
                mRobot997.getLeftEncoder().reset();
                mRobot997.getRightEncoder().reset();
                mRobot997.getGyro().reset();
            }
            // Latch the kicker.
            if (mRightStick.getRawButton(6)) {
                mRobot997.driveLatchSolenoid(1);
                //Wait for button to be released.
                while (mRightStick.getRawButton(6)) {
                    Thread.yield();
                }
            }
            //Unlatch the kicker.
            if (mRightStick.getRawButton(7)) {
                mRobot997.driveLatchSolenoid(0);
                //Wait for button to be released.
                while (mRightStick.getRawButton(7)) {
                    Thread.yield();                                              }
            }

            // Flush the kicker.
            if (mRightStick.getRawButton(10)) {
                mRobot997.driveShooterSolenoid(0);
                //Wait for button to be released.
                while (mRightStick.getRawButton(10)) {
                    Thread.yield();
                }
            }

            //Charge the Kicker.
            if (mRightStick.getRawButton(11)) {
                mRobot997.driveShooterSolenoid(1);
                //Wait for button to be released.
                while (mRightStick.getRawButton(11)) {
                    Thread.yield();
                }
            }
            if (mLeftStick.getRawButton(4)){
                mRobot997.switchBallHolder(mRobot997.Forward);
                //Wait for button to be released.
                while (mLeftStick.getRawButton(4)) {
                    Thread.yield();
                }
            }
            if (mLeftStick.getRawButton(3)){
                mRobot997.switchBallHolder(mRobot997.Off);
                //wait for button to be released
                while(mLeftStick.getRawButton(3)){
                    Thread.yield();
                }
            }

            if (mLeftStick.getRawButton(5)){
                mRobot997.switchBallHolder(mRobot997.Reverse);
                //wait for button to be released
                while(mLeftStick.getRawButton(5)){
                    Thread.yield();
                }
            }

            /*
            if (mLeftStick.getRawButton(2)) {
            mRobot997.raiseLifter();
            }
            if (mLeftStick.getRawButton(3)) {
            mRobot997.extendLifter();
            }

            if (mLeftStick.getRawButton(4)) {
            mRobot997.performLift();
            }

             */
            Thread.yield();
            Timer.delay(0.0005);
        }
    }
}


